package io;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import view.Canvas;
import view.Designer;
import model.Prescription;/** * A class to encapsulate the exporting to an image functionality for the designer * @author Daniel Bond, Mohammed Abdullah, Gideon Pyzer */
public class ExportImage {
	
	/**
	 * Exports the current Prescription view to a JPG file
	 * @throws IOException 
	 */
	public static void export(File selected, String selectedFilterExt) throws IOException {
		Prescription prescription =Prescription.getInstance();
		Canvas canvas = Canvas.getInstance();
		
		int type = BufferedImage.TYPE_INT_RGB;
		BufferedImage image = new BufferedImage(prescription.getWidth(), prescription.getHeight(), type);
		Graphics2D g2 = image.createGraphics();
		canvas.paint(g2);
		ImageIO.write(image,selectedFilterExt,selected);		Designer.getInstance().showMessageDialog("Prescription was successfully saved in " + selectedFilterExt +" format.");
	}
}
